//hunter.txt - Same as talknpc except that, if it is ever hostile, will immediately 
//hunt down the pc and attack.
// Memory Cells:
//   Cell 0 - golem number (15-18)
//   Cell 1 - Number of state when talked to. Plays default text if 0.
//   Cell 2,3 -  Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	Cell 4 - Range to hunt from. If left at 0, defaults to 40.
begincreaturescript;

variables;

short i,target;
short awake_level = 0;
short awake_count = 0;
short last_abil;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();
	set_name(ME,"Awakening Golem");
	set_level(ME,35);
	set_boss_level(ME,1);
	set_summon_level(ME,1);
	set_act_at_dist(ME,1);
	set_new_abil(ME,20);
	
	awake_level = get_memory_cell(0) - 14;
	awake_level = awake_level * 3;
	break;

beginstate DEAD_STATE;
	sf(70,get_memory_cell(0),2);
break;

beginstate START_STATE; 
	if ((gf(70,20) > 0) && (tick_difference(last_abil,get_current_tick()) > 0)) {
		damage_char(ME,300,0);
		last_abil = get_current_tick();
		}
	if (gf(70,get_memory_cell(0)) > 1) 	
		end();
	
	if (gf(70,21) < awake_level)
		end();
	if ((gf(70,21) >= awake_level) && (awake_count < 4)) {
		if (awake_count == 0) {
			awake_count = 1;
			last_abil = get_current_tick();
			}
			else {
				if (tick_difference(last_abil,get_current_tick()) > 1) {
					awake_count = awake_count + 1;
					last_abil = get_current_tick();
				  	place_particle_num(ME,0,6,8);
					if (awake_count < 4)
						print_named_str(ME,"is slowly coming to life.");
						else {
							set_name(ME,"Radiant Golem");
							print_named_str(ME,"is now fully active.");
							set_attitude(ME,10);
							}
					}
				}
		end();
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if (get_attitude(ME) >= 10) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();

break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	if ((is_combat()) && (gf(70,get_memory_cell(0)) == 0) &&	
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();
		  	place_particle_num(ME,2,4,8);
			print_named_str(ME,"surrounds itself with a curtain of flame.");
			pc_heard_sound_delay(117,250);						
	  		create_missile_spiral(154,40,8,2);
	  		damage_nearby(get_ran(1,150,200),8,2,0);

		end();
		}

	do_attack();
break;

beginstate TALKING_STATE;
	sf(70,19,get_memory_cell(0));
	if (gf(70,get_memory_cell(0)) > 0) {
		print_str("This golem has already been disabled.");
		}
		else begin_talk_mode(70);
break;